import React from 'react';
import { Alert } from 'react-native';
import { Scene, Actions, ActionConst } from 'react-native-router-flux';
import user from '../../../common/models/user';
import navBarStyle from '../../../components/navBarStyle';
import Form from '../../../components/Form';
import NavBarIconBtn from '../../../components/NavBarIconBtn';
import CheckOrg from './chooseOrg';
import JoinOrg from './joinOrg';

/* TODO
如果使用Actions.replace('key', [options])跳转，
那么在Scene标签里设置的额外属性将无法传入相关Component， 仅有options里的属性可以传入；
解决方案：可以通过设置Scene标签的type为replace，来实现上述替换跳转
*/

const setInstitutionId = ({insuranceOrgId}) => {
  user.setInstitutionId(insuranceOrgId).then(institutionId => {
    if (institutionId) {
      Actions.inputInstitutionInfo({ institutionId });
    } else {
      Alert.alert('错误', `无效机构编码-${values}`, [
        {text: '重试'}
      ])
    }
  });
};
const pressHandle = values => {
  user.update(values).then(data => {
    if (data) {
      Alert.alert('操作成功', '已经提交加入机构申请, 请等候审核...', [
        { text: '知道了', onPress: Actions.pop }
      ]);
    }
  });
};

module.exports = [
  <Scene
    key="checkInstitution"
    component={CheckOrg}
    title="确认加入机构"
    path="/checkInstitution"
    {...navBarStyle}
    user={user}
    hideTabBar
  />,
  <Scene
    key="inputInstitutionInfo"
    component={JoinOrg}
    title="提交加入申请"
    path="/joinInstitution"
    {...navBarStyle}
    user={user}
    hideTabBar
    type={ActionConst.REPLACE}
  />
];
